package cn.est.util;

import cn.est.dto.Result;

public class ResultUtil {
    private static final String SUCCESS_CODE = "0";
    private static final String SUCCESS_MSG = "操作成功";
    private static final String DEFAULT_ERROR_CODE = "1";
    private static final String DEFAULT_ERROR_MSG = "操作失败";

    public static <T> Result<T> buildResult(String code,String mag,T data){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(mag);
        result.setData(data);
        return result;
    }

    public static Result success(String code,String msg) {
        return buildResult(code,msg,null);
    }

    public static <T> Result<T> success(T data) {
        return buildResult(SUCCESS_CODE,SUCCESS_MSG,data);
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    public static Result error(String code,String msg) {
        return buildResult(code,msg,null);
    }

    public static<T> Result<T> error(T data) {
        return buildResult(DEFAULT_ERROR_CODE,DEFAULT_ERROR_MSG,data);
    }

    public static Result error() {
        return error(null);
    }
}
